<template>
  <div class="book-cover-wrapper">
    <img v-if="src" class="book-cover" :src="src | handleImageUrl" alt="" />
    <van-icon v-else class="book-cover-default" name="photo" />
    <span v-if="book.tag" class="book-tag">{{ book.tag }}</span>
  </div>
</template>

<script>
export default {
  props: {
    src: {
      typpe: String
    },
    book: {
      type: Object,
      default: () => {
        return {
          src: '',
          tag: ''
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.book-cover-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: #eee;
  border-radius: 6px;
  overflow: hidden;
  .book-cover {
    width: 100%;
    height: 100%;
    margin: 0 auto;
    max-width: 100%;
    max-height: 100%;
    border-radius: 6px;
    box-sizing: border-box;
    object-fit: cover;
  }

  .book-cover-default {
    width: 100%;
    text-align: center;
    font-size: 50px;
    color: #ddd;
  }
  .book-tag {
    position: absolute;
    top: 0;
    right: 0;
    color: #fff;
    padding: 2px 6px;
    font-size: 12px;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.5);
  }
}
</style>
